package com.study.d5_set;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        Set<Girl> set = new TreeSet<>();
        set.add(new Girl("陈",'女',20,165.3));
        set.add(new Girl("六",'女',22,155.3));
        set.add(new Girl("流",'女',80,168.3));
        set.add(new Girl("黄",'女',10,167.3));
        //实现comparable类，重写compareto方法
        System.out.println(set);

        Set<Girl> set2 = new TreeSet<>(new Comparator<Girl>() {
            @Override
            public int compare(Girl o1, Girl o2) {
                return Double.compare(o1.getHeight(),o2.getHeight());
            }
        });
        set2.add(new Girl("陈",'女',20,165.3));
        set2.add(new Girl("六",'女',22,155.3));
        set2.add(new Girl("流",'女',80,168.3));
        set2.add(new Girl("黄",'女',10,167.3));
        System.out.println(set2);
    }
}
